package fatboy.hypeerweb;

import java.io.Serializable;

/**
 * Base pointer class for edge and Node pointers
 * @author James
 * 
 * @domain valid Node input
 */
abstract class NodePointer implements Comparable<NodePointer>, Serializable{
	private Node node;
	private NodeType typeOfNode;
	
	public NodePointer(Node nodeIn) {
		node = nodeIn;
	}
	
	/**
	 * Compares 2 node pointers
	 * @precondition o is a valid NodePointer object
	 * @post returns comparison of NodeType address
	 * @return Integer
	 */
	public abstract int compareTo(NodePointer o);
	//public abstract NodeType getType();

	/**
	 * Checks whether 2 node pointers are equal
	 * @precondition o is a valid NodePointer object
	 * @post returns true if the two objects are equal, false in all other cases
	 * @return boolean
	 */
	public abstract boolean equals(Object o);

	
	/**
	 * Returns the reference of the node it
	 * @precondition valid NodePointer has been created
	 * @post returns valid node Object
	 * @return the node stored in the pointer 
	 */
	public Node getNode() {
		return node;
	}
	
	public String toString(){
		return node.getAddress().toString();
	}
	
	/**
	 * Does type comparison if Surrogate or Edge pointer
	 * 
	 * @precondition NodePointer exists and other is valid NodePointer object
	 * @post returns boolean comparison of objects based on NodeType
	 */
	public boolean isSameType(NodePointer other){
		//System.out.println(node.getNodeType()+" Other: "+other.node.getNodeType());
		return getTypeOfNode().equals(other.getTypeOfNode());
	}
	
	/**
	 * set nodeType for pointer
	 * 
	 * @precondition valid nodeType passed
	 * @post all set correctly
	 */
	public void setTypeOfNode(NodeType typeOfNode) {
		this.typeOfNode = typeOfNode;
	}

	
	/**
	 * returns nodeType
	 * 
	 * @precondition true
	 * @post returns nodeType
	 */
	public NodeType getTypeOfNode() {
		return typeOfNode;
	}
}
